package swing;

import javax.swing.JFrame;
import javax.swing.JPanel;

import java.awt.GridBagLayout;

import javax.swing.JLabel;

import java.awt.GridBagConstraints;

import javax.swing.JTextPane;

import java.awt.Insets;

import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.URL;

import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.ImageIcon;

import travel.Travel_Information_VO;
import travel.region.Region_DAO;
import java.awt.Font;
import java.awt.Color;




public class home extends JPanel {
	private JTextField textField;
	private String imgPath = "/image/";
	private String imgExt = ".jpg";
	private String img = "ation";
	final Region_DAO rd= new Region_DAO();
	private int count = 1;
	public home() {
		setLayout(null);
		JLabel lblNewLabel = null;
		setBackground(Color.black);
		for( Travel_Information_VO tiv : rd. votesImage()){
		lblNewLabel = new JLabel("이번 최고 추천 여행지는 "+tiv.getRegion_name()+"에 있는 "+tiv.getTravel_place()+"입니다!");
		}
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setFont(new Font("맑은 고딕", Font.BOLD, 20));
		lblNewLabel.setBounds(41, 292, 506, 34);
		lblNewLabel.setForeground(new Color(248, 248, 255));
		add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel();// 추천 이미지 
		for ( Travel_Information_VO tiv : rd.votesImage() ){
		lblNewLabel_1.setIcon(new ImageIcon(home.class.getResource("/image/"+tiv.getTravel_image_name()+".jpg")));
		}
		lblNewLabel_1.setBounds(41, 336, 870, 190);
		add(lblNewLabel_1);
//		add(makeButton1(asd));
		
		
		
		JButton btnNewButton = new JButton("추천 여행지 가기");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JFrame p = new JFrame();
				GiyucEvent eventUp =  null;
				for(Travel_Information_VO tiv : rd.votesImage()){
					eventUp = new GiyucEvent( p, tiv.getRegion_name() );
				}
				eventUp.show();
			}
		});
		btnNewButton.setBounds(779, 536, 132, 23);
		add(btnNewButton);
		
		textField = new JTextField();
		textField.setEditable(false);
		textField.setAutoscrolls(false);
		textField.setFont(new Font("맑은 고딕", Font.BOLD, 20));
		for(Travel_Information_VO tiv : rd.votesImage()){
		textField.setText(""+tiv.getTravel_votes()+"");
		}
		textField.setBounds(745, 536, 30, 23);
		add(textField);
		textField.setColumns(10);
		
		JLabel label = new JLabel("홈 이미지!");
		label.setIcon(new ImageIcon(home.class.getResource("/image/santo_320_1.jpg")));
		label.setBounds(41, 10, 870, 86);
		add(label);
		add(makeButton1(count));
		
		JLabel lblNew_votes = new JLabel("");
		lblNew_votes.setIcon(new ImageIcon(home.class.getResource("/image/icon.png")));
		lblNew_votes.setBounds(712, 536, 30, 23);
		add(lblNew_votes);
	}
		
	private JButton makeButton1(int cleck) {
		final JButton 하와이 = new JButton();
		
		
		하와이.setFocusPainted(false);
		하와이.setActionCommand(img);
		
		System.out.println(cleck);

		URL iconPach = getClass().getResource(	"/image/ation"+cleck+".jpg");
		
		하와이.setIcon( new ImageIcon(iconPach));
		
하와이.addActionListener(new ActionListener() {
	
			@Override
			public void actionPerformed(ActionEvent e) {
				
				count++;
				if(count == 4){
					base ba = new base();
					count = 1;

				}
				URL iconPach = getClass().getResource(	"/image/ation"+count+".jpg");
				
				하와이.setIcon( new ImageIcon(iconPach));
				
//				JScrollPane scrollPane = new JScrollPane();
//				scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
//				home load2 = new home();
//				scrollPane.setViewportView(load2);
				
			}
		} 
		);

		하와이.setBounds(41, 117, 870, 128);
		return 하와이;
	}
}
			
		
		
	

	
	